package com.qixin.modules.log.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qixin.modules.log.entity.SysInterfaceLog;
import com.qixin.modules.log.entity.SysInterfaceLogLongtext;
import com.qixin.modules.log.mapper.SysInterfaceLogLongtextMapper;
import com.qixin.modules.log.mapper.SysInterfaceLogMapper;
import com.qixin.modules.log.service.ISysInterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 接口使用日志
 * @Author: wmf
 * @Date:   2022-02-23
 * @Version: V1.0
 */
@Service
public class SysInterfaceLogServiceImpl extends ServiceImpl<SysInterfaceLogMapper, SysInterfaceLog> implements ISysInterfaceLogService {

    @Autowired
    SysInterfaceLogLongtextMapper longtextMapper;

    @Override
    public void saveInterfaceLog(SysInterfaceLog entity) {
        if (entity.getContent() != null && entity.getContent().length() > 65500){
            SysInterfaceLogLongtext logLongtext = new SysInterfaceLogLongtext();
            logLongtext.setContent(entity.getContent());
            entity.setContent("内容长度超出65535，保存到大字段表");
            this.baseMapper.insert(entity);
            logLongtext.setInterfaceLogId(entity.getId());
            longtextMapper.insert(logLongtext);
        }else {
            this.baseMapper.insert(entity);
        }
    }

}
